package com.flnet.web.controller.foxwash;

import com.flnet.common.annotation.Log;
import com.flnet.common.base.AjaxResult;
import com.flnet.common.enums.BusinessType;
import com.flnet.common.page.TableDataInfo;
import com.flnet.common.utils.UUIDUtils;
import com.flnet.common.utils.poi.ExcelUtil;
import com.flnet.foxwash.domain.WMember;
import com.flnet.foxwash.domain.WVendor;
import com.flnet.foxwash.service.IWMemberService;
import com.flnet.framework.util.ShiroUtils;
import com.flnet.framework.web.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员 信息操作处理
 * 
 * @author flnet
 * @date 2019-03-20
 */
@Controller
@RequestMapping("/foxwash/wMember")
public class WMemberController extends BaseController
{
    private String prefix = "foxwash/wMember";
	
	@Autowired
	private IWMemberService wMemberService;
	
	@RequiresPermissions("foxwash:wMember:view")
	@GetMapping()
	public String wMember()
	{
	    return prefix + "/wMember";
	}
	
	/**
	 * 查询会员列表
	 */
	@RequiresPermissions("foxwash:wMember:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WMember wMember)
	{
		startPage();
        List<WMember> list = wMemberService.selectWMemberList(wMember);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出会员列表
	 */
	@RequiresPermissions("foxwash:wMember:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WMember wMember)
    {
    	List<WMember> list = wMemberService.selectWMemberList(wMember);
        ExcelUtil<WMember> util = new ExcelUtil<WMember>(WMember.class);
        return util.exportExcel(list, "wMember");
    }
	
	/**
	 * 新增会员
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存会员
	 */
	@RequiresPermissions("foxwash:wMember:add")
	@Log(title = "会员", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WMember wMember)
	{
		wMember.setUuid(UUIDUtils.getUUID());
		wMember.setCreator(ShiroUtils.getUserId());
		return toAjax(wMemberService.insertWMember(wMember));
	}

	/**
	 * 修改会员
	 */
	@GetMapping("/edit/{memberId}")
	public String edit(@PathVariable("memberId") Long memberId, ModelMap mmap)
	{
		WMember wMember = wMemberService.selectWMemberById(memberId);
		mmap.put("wMember", wMember);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存会员
	 */
	@RequiresPermissions("foxwash:wMember:edit")
	@Log(title = "会员", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WMember wMember)
	{
		wMember.setModifier(ShiroUtils.getUserId());
		return toAjax(wMemberService.updateWMember(wMember));
	}
	
	/**
	 * 删除会员
	 */
	@RequiresPermissions("foxwash:wMember:remove")
	@Log(title = "会员", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wMemberService.deleteWMemberByIds(ids));
	}

	/**
	 * 服务状态修改
	 */
	@Log(title = "会员管理", businessType = BusinessType.UPDATE)
	@RequiresPermissions("foxwash:wMember:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(WMember wMember)
	{
		return toAjax(wMemberService.changeStatus(wMember));
	}
}
